package com.desay.pangoo.itmt.entity;

import java.io.Serializable;
import java.util.Objects;
import java.util.Set;

import javax.persistence.*;

import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.Data;

/**
 * tech_online_review_relevant 相关性review
 * 
 * @author uidq1163
 *
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "tech_online_review_relevant", uniqueConstraints = {
		@UniqueConstraint(columnNames = { "creator", "tech_online_review_id", "work_group_id" }) })
@JsonIgnoreProperties({ "techOnlineReview" })
@Data
public class TechOnlineReviewRelevantEntity extends BaseEntity implements Serializable {

	private static final long serialVersionUID = 973410772603544095L;

	@javax.persistence.Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", columnDefinition = "bigint COMMENT '主键'")
	private Long id;

	@Column(name = "is_relevant", nullable = true, columnDefinition = "bit COMMENT '是否相关'")
	private Boolean isRelevant;

	@Column(name = "audit_or_not", nullable = true, columnDefinition = "bit COMMENT '是否旁听'")
	private Boolean auditOrNot;

	@Column(name = "description", nullable = true, columnDefinition = "mediumtext COMMENT '说明'")
	private String description;

	@ManyToOne(fetch = FetchType.EAGER, optional = true)
	@JoinColumn(name = "tech_online_review_id")
	@JsonIgnoreProperties({ "parent", "children" })
	private TechOnlineReviewEntity techOnlineReview;

	/** 关联TMT用户信息 */
	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinColumn(name = "relevant_id")
	@JsonIgnoreProperties("techOnlineReview")
	private Set<TechOnlineReviewTMTEntity> tmtInfos;

	@ManyToOne(fetch = FetchType.EAGER, optional = true)
	@JoinColumn(name = "work_group_id")
	private WorkGroupEntity workGroup;

	/**
	 * 创建者
	 */
	@Column(name = "creator_name", nullable = true, insertable = true, updatable = false, columnDefinition = "varchar(255) COMMENT '创建者'")
	private String creatorName;

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (!super.equals(obj)) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		TechOnlineReviewRelevantEntity other = (TechOnlineReviewRelevantEntity) obj;
		return Objects.equals(auditOrNot, other.auditOrNot) && Objects.equals(creatorName, other.creatorName)
				&& Objects.equals(description, other.description) && Objects.equals(id, other.id)
				&& Objects.equals(isRelevant, other.isRelevant)
				&& Objects.equals(techOnlineReview, other.techOnlineReview) && Objects.equals(tmtInfos, other.tmtInfos)
				&& Objects.equals(workGroup, other.workGroup);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + Objects.hash(auditOrNot, creatorName, description, id, isRelevant, workGroup);
		return result;
	}
}
